package org.go.expcetion;

import org.go.scheduler.Scheduler;

/**
 * Base class for exceptions thrown by the Go <code>{@link Scheduler}</code>.
 * 
 * <p>
 * <code>SchedulerException</code>s may contain a reference to another
 * <code>Exception</code>, which was the underlying cause of the <code>SchedulerException</code>.
 * </p>
 * 
 * @author hejie
 */
public class GoException extends Exception {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7713700478760507594L;

	public GoException() {
		super();
	}

	public GoException(String msg) {
		super(msg);
	}

	public GoException(String msg, Throwable cause) {
		super(msg, cause);
	}

	public GoException(Throwable cause) {
		super(cause);
	}

	/**
	 * <p>
	 * Return the exception that is the underlying cause of this exception.
	 * </p>
	 * 
	 * <p>
	 * This may be used to find more detail about the cause of the error.
	 * </p>
	 * 
	 * @return the underlying exception, or <code>null</code> if there is not
	 *         one.
	 */
	public Throwable getUnderlyingException() {
		return super.getCause();
	}

	@Override
	public String toString() {
		Throwable cause = getUnderlyingException();
		if (cause == null || cause == this) {
			return super.toString();
		} else {
			return super.toString() + " [See nested exception: " + cause + "]";
		}
	}
}
